package com.learn.xueer.ui.adapter

import android.media.MediaMetadataRetriever
import android.media.MediaPlayer
import android.net.Uri
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.LinearLayout
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.learn.xueer.R
import com.learn.xueer.data.model.bean.HearSayQuestionResourceItem

class SubmitHearSayAdapter(data: ArrayList<HearSayQuestionResourceItem>) :
    BaseQuickAdapter<HearSayQuestionResourceItem, BaseViewHolder>(
        R.layout.submit_hear_say_test, data
    ) {

    private var resMain = ""
    private var answerList: ArrayList<String>? = null
    override fun convert(holder: BaseViewHolder, item: HearSayQuestionResourceItem) {
        holder.setText(R.id.tvTitle, item.templateSettings.content)
        val questionInfo = item.questions.first()
        if (questionInfo.trunk.attachments.first().fileType == 2) {
            holder.setVisible(R.id.tvContent, true)
            holder.setVisible(R.id.imageContent, false)
            holder.setText(R.id.tvContent, questionInfo.trunk.body)
        } else {
            holder.setVisible(R.id.tvContent, false)
            holder.setVisible(R.id.imageContent, true)
            Glide.with(context)
                .load(resMain + questionInfo.trunk.attachments.first().url)
                .into(holder.getView(R.id.imageContent))
        }
        if (answerList == null) {
            holder.getView<LinearLayout>(R.id.myAudio).visibility = GONE
            holder.setText(R.id.btnSubmit, "去做题")
        } else {
            val adapterPosition = holder.adapterPosition
            if (adapterPosition > answerList!!.size) {
                holder.getView<LinearLayout>(R.id.myAudio).visibility = GONE
                holder.setText(R.id.btnSubmit, "去做题")
            } else {
                holder.getView<LinearLayout>(R.id.myAudio).visibility = VISIBLE
                holder.setText(R.id.btnSubmit, "重做该题")
            }
        }
    }

    fun setResMain(resMain: String) {
        this.resMain = resMain
    }

    fun setAnswerList(answerList: ArrayList<String>?) {
        this.answerList = answerList
    }

}